package service

import (
	"os"
	"time"

	"github.com/go-redis/redis/v7"
)

func initRedis() (Redis *redis.Client) {
	if Conf.Redis.Enable {
		Redis = redis.NewClient(&redis.Options{
			Addr:        Conf.Redis.Addr,
			Password:    Conf.Redis.Password,
			DB:          Conf.Redis.DB,
			DialTimeout: time.Duration(Conf.Redis.Timeout) * time.Second,
		})

		pong, err := Redis.Ping().Result()
		if err != nil {
			Log.Sugar().Errorf("redis conn error: %s,%v", pong, err.Error())
			os.Exit(-1)
		}
		Log.Info("redis 初始化连接成功")
	}
	return
}
